// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently

#pragma once

#ifndef STRICT
#define STRICT
#endif

#include "targetver.h"

#define X32_X64_SYSTEM//for outlook x32 on windows 7 x64, possibly the same for vista x64

#define OFFICEVERSION 12
#define OFFICEVER(x) #x

#define _ATL_APARTMENT_THREADED
#define _ATL_NO_AUTOMATIC_NAMESPACE

#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS	// some CString constructors will be explicit

#include "resource.h"
#include <atlbase.h>
#include <atlcom.h>
#include <atlctl.h>
#include <iostream>
#include <sstream>
#include <string>

using namespace ATL;

#ifdef X32_X64_SYSTEM

#import "C:\Program Files (x86)\Common Files\Designer\MSADDNDR.DLL" raw_interfaces_only, raw_native_types, no_namespace, named_guids, auto_search
#import "C:\Program Files (x86)\Common Files\Microsoft Shared\Office12\mso.dll" rename_namespace("Office"), raw_interfaces_only, raw_native_types, named_guids, auto_search
using namespace Office; 
#import "C:\Program Files (x86)\Microsoft Office\Office12\MSOUTL.olb" rename_namespace("Outlook"), named_guids, raw_interfaces_only
using namespace Outlook;
#else

#import "C:\Program Files\Common Files\Designer\MSADDNDR.DLL" raw_interfaces_only, raw_native_types, no_namespace, named_guids, auto_search
#import "C:\Program Files\Common Files\Microsoft Shared\Office12\mso.dll" rename_namespace("Office"), named_guids 
using namespace Office; 
#import "C:\Program Files\MSOffice\Office12\MSOUTL.olb" rename_namespace("Outlook"), named_guids, raw_interfaces_only
using namespace Outlook;

#endif

typedef std::basic_string<TCHAR> tstring; // string of TCHARs

template < class ContainerT >
void tokenize(const tstring& str, ContainerT& tokens, const tstring& delimiters = " ", const bool trimEmpty = false)
{
   tstring::size_type pos, lastPos = 0;
   while(true)
   {
      pos = str.find_first_of(delimiters, lastPos);
      if(pos == tstring::npos)
      {
         pos = str.length();

         if(pos != lastPos || !trimEmpty)
            tokens.push_back(ContainerT::value_type(str.data()+lastPos, (ContainerT::value_type::size_type)pos-lastPos ));

         break;
      }
      else
      {
         if(pos != lastPos || !trimEmpty)
            tokens.push_back(ContainerT::value_type(str.data()+lastPos, (ContainerT::value_type::size_type)pos-lastPos ));
      }

      lastPos = pos + 1;
   }
};

template <class T>
inline std::string to_string (const T& t)
{
	std::stringstream ss;
	ss << t;
	return ss.str();
};
